<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common_New.jsp" %>

<%@ page import="com.limao.servlet.WebFunction" %>
<%@ page import="com.limao.DBDataClass.CrowdVRHomeClass" %>
<%@ page import="com.limao.DBDataClass.CrowdVrSysGoodsClass" %>
<%@ page import="com.limao.CacheManager.CrowdVrGoodsCache" %>
<%@ page language="java" import="com.limao.DBDataClass.CrowdUserAuthClass"%>

<%
	String userid=CacheClass.isLogin(request,response);
    if (CacheClass.getIntValue(userid) == 0) {
        out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
        return;
    }
    
 CrowdUserAuthClass user= WebFunction.getUserInfo(request,response);
 if(user==null)
 {
	 out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
	 return;
 } 
 
    String pwdMd5= WebFunction.getUserPwd(request,response);
 
    CrowdVRHomeClass vrhome = WebFunction.getVrHomeInfo(request, response);

    List<CrowdVrSysGoodsClass> tmplist = CrowdVrGoodsCache.getInstance().Load_CrowdVRGoods();
    
    
    Date d=new Date();
    //当天的前一天时间
    //d=CacheClass.getDateAfterDay(d, 10);
    String enddayVal=CacheClass.getDateBeforeDay4(d, 1);
    //当天的前30天时间
    String startdayVal=CacheClass.getDateBeforeDay4(d, 15);
   
    
%>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>市场</title>
    <link rel="stylesheet" href="mb/css/common.css" />
    <link rel="stylesheet" href="mb/css/all_New.css" />
    <script src="mb/js/echarts.min.js"></script>
    <script type="text/javascript" src="mb/js/charts_zd.js"></script>
</head>
<body ontouchstart="">
<div class="theme-popover-mask"></div>
<div class="detailTop pf w100 of">
    <div class="w100 of tc c3 f18">
        <span class="pa" style="left: 5px;" onclick="javascript:history.back();"><img src="mb/images/top_back.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        市场
        <div class="dib of pa" style="right: 10px;">
            <a href="mb/jsp/saveMoney.jsp" class="dib tc">金额转入</a>
        </div>
    </div>
</div>

<div class="container jz" style="margin-top: 41px;">
    <section class="proSection w100 bcfb">
        <form class="detailInfo w100 of">
            <label for="proKind" class="f14 c3 mgl10">现货品种</label>
            <select name="proKind" id="proKind">

               
            </select>
            
        </form>
        
    </section>
    
    


    <section id="introDetail" class="w100 of">
        <div class="w100 of bcfb">
            <ul id="qz-Tab" class="picTab w100">
                <li data="1" class="pictab_current">分时</li>
                <li data="5" class="">5分钟<span class="line"></span></li>
                <li data="15" class="">15分钟<span class="line"></span></li>
                <li data="30" class="">30分钟<span class="line"></span></li>
                <li data="60" class="">60分钟<span class="line"></span></li>
                <li data="100" class="">日线<span class="line"></span></li>
            </ul>
            <div class="picTabBottomLine w100 "></div>
        </div>
      
        
<!--         
        <div id="qz-TabContent" class="introtab_content w100 of bcf" style='margin-left: -10px;'>
            <div class="w100 of bcf" style="display: block;margin-left:5px;margin-right:5px;" id="mins_chartDiv">
                    <iframe class="w100 h100 of" src="mb/jsp/mins.jsp" frameborder="0" scrolling="no"  vsspace="0" hspace="0" marginwidth="0" marginheight="0">
        			</iframe>
             </div>
             <div style="display: none;margin-left:5px;margin-right:5px;" id="K_chartDiv">
                    <iframe class="w100 h100 of" id="K_iframe" src="mb/jsp/k-painter.jsp" frameborder="0" scrolling="no"  vsspace="0" hspace="0" marginwidth="0" marginheight="0">
        			</iframe>
             </div>
        </div>
-->  
		<div class="pricetab_content w100 of bcf" style="background: #060606;margin: 0 auto;">
            <ul class="baseDateTab w100" >
                <li >&nbsp;&nbsp;当前:<span id="curChartPrice"></span></li>
                <li >开市:<span id="openChartPrice"></span></li>
                <li >最高:<span id="highChartPrice"></span></li>
                <li >最低:<span id="lowChartPrice"></span></li>
            </ul>
		</div>
        <div id="charts_ct" class="charttab_content w100 of bcf pr" style="background: #060606;margin: 0 auto;">
        	<p class="pa tr cred f12" style="display:none;z-index:20;top:10px;right:10px;padding:4px 4px;background: #ffffff;"  id="mess"><p>
			<div id="charts1" class="chart"></div>
			<div id="charts2" class="chart"></div>
		</div>

        
    </section>
    <script>
        //tab切换
        $(function () {
        	var heightAuto = $(window).height();
        	var widthAuto = $(window).width();
        
        	$('#qz-TabContent').css('width',heightAuto);
        	
        	$('#mins_chartDiv').css('width',widthAuto);
        	$('#mins_chartDiv').css('height',widthAuto*0.7+10);
 
        	$('#K_chartDiv').css('width',widthAuto);
        	$('#K_chartDiv').css('height',widthAuto*0.7+10);       	 
        	 
        	 
        
            $('.picTab>li').mouseover(function () {
                var contentindex = $(this).index();
                $('.picTab>li').removeClass();
                $(this).addClass('pictab_current');
                
                if(contentindex==0)
                {
                    $('.charttab_content>div').eq(0).css('display', 'block');
                    $('.charttab_content>div').eq(1).css('display', 'none');                        	
                }
                else
                {
                   $('.charttab_content>div').eq(0).css('display', 'none');
                   $('.charttab_content>div').eq(1).css('display', 'block');
                   
                }
            });
            
            $("#proKind").change(function () {
                                            var optionText = $(this).find("option:selected").text();
                                            //console.log(optionText);
                                               
                                            var optionValue = $(this).find("option:selected").val();	           		
                                            //console.log(optionValue);	           			
						           			SetcfgObj(optionValue);
					           				chartsinit(cfgObj);
					           				
            });
            
        });
    </script>

    <section class="w100 of bcfb" >
        <div class="w100 of bcfb">
            <ul class="jiaoyiTab w100 bcf">
                <li class="jiaoyiTab_current"><img id="jiaoyi" src="mb/images/jiaoyi1.png">交易</li>
                <li class=""><img id="chicang" src="mb/images/chicang.png"/>订单<span class="line"></span></li>
                <li class=""><img id="jilu" src="mb/images/jilu.png" style="height:21px"/>记录<span class="line"></span>
                </li>
                <li class=""><img id="wodezichan" src="mb/images/wodezichan.png" style="height:20px"/>我的金额<span
                        class="line"></span></li>
            </ul>
            <div class="picTabBottomLine2 w100 "></div>
        </div>
        <div class="jiaoyiTab_content w100 of pr">
            <article class="w100" style="display: block;">
            	<div class="w100 mgb32" style="border-bottom: 1px solid #ddd;">
            		<div class="w100 cred clearfix of guaPai" style="margin:0;">
            			<p class="col-1 fl f12 tc">销售区挂牌</p>
            			<div class="col-2 fl f13"><p class="fl">价格：<span class="f14" id="nowprice1"></span></p><p class="fl">量：<span class="f14" id="amount1"></span></p></div>
            			<p class="col-3 fl radioDirect"><input type="radio" checked="checked" name="direct" value="B" id="type1"  onclick="zhaiPai(0,$(this));" /><label for="type1" class="up">摘牌</label> </p>
            		</div>
            		<div class="w100 cgreen clearfix of guaPai" style="margin:0;">
            			<p class="col-1 fl f12 tc">采购区挂牌</p>
            			<div class="col-2 fl f13"><p class="fl">价格：<span class="f14" id="nowprice2"></span></p><p class="fl">量：<span class="f14" id="amount2"></span></p></div>
            			<p class="col-3 fl radioDirect"><input type="radio"  name="direct" value="S" id="type2"  onclick="zhaiPai(1,$(this));" /><label for="type2" class="down">摘牌</label></p>
            		</div>
            	</div>
            	
                <div class="articleJz">
	                	<div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3" style="width: 69px;">可用余额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18" id="totalenablermb"></span><span class="f14"></span>
	                    </div>
	                    <div class="fl cff9933">
	                        <span class="f12 c3" style="width: 69px;">手续费</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18" id="totalBuyRmbRate"></span><span class="f14"></span>
	                    </div>
	                </div>
	                <div class="jydiv clearfix of">
	                     <div class="fl cff9933">
                        <span class="f12 c3" style="width: 69px;">订货金额</span><span class="mgl7 f14">&yen;</span><span
                            class="f18" id="totalBuyRmb"></span><span class="f14"></span>
	                        <input type="hidden"  id="price"  />
	                    </div>
	                    <div class="fl cff9933">
	                        <span class="f12 c3" style="width: 69px;">订货数量</span><input type="number"  name="num" id="num" min="0" onblur="UpdateBuyRmb();" class="jyInput dib f12 c3 mgl7" onkeyup="value=this.value.replace(/\D+/g,'')"/>
	                    </div>
	                </div>
	                 <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3" style="width: 69px;">盈利转让(%)</span><input type="number"  name="tppercent" id="tppercent" min="1" placeholder="不能超过100" class="jyInput dib f12 c3 mgl7" onkeyup="value=this.value.replace(/\D+/g,'')"/>
	                    </div>
	                    <div class="fl cff9933">
	                        <span class="f12 c3" style="width: 69px;">亏损转让(%)</span><input type="number"  name="slpercent" id="slpercent" min="1" placeholder="不能超过90" class="jyInput dib f12 c3 mgl7" onkeyup="value=this.value.replace(/\D+/g,'')"/>
	                    </div>
	                </div>
	                <div class="clearfix of">
	                    <div class="vsDiv pr of">
	                    	<p id="redTest-pai" class="w100 tc c9 f12 lh2">当前操作为：<span class="cred">销售区摘牌（买）</span></p>
	                    	<p id="greenTest-pai" class="w100 tc c9 f12 lh2">当前操作为：<span class="cgreen">采购区摘牌（卖）</span></p>
	                        <a href="javascript:void(0);" onclick="Buy();" class="db f16 cf tc jz" style="background:#3399ff">确定摘牌</a>
	                        <div class="pa w100 h100" style="top:0;left: 0;z-index:-1;">
	                            <div class="w100 h100">
	                                <img src="mb/images/vs.png" class="db jz">
	                            </div>
	                        </div>
	                    </div>
	                </div>
	                <div class="vciLine w92 jz pr">
	                    <div class="pa w100">
	                        <span class=" f12 c9">市场有风险  参与需谨慎</span>
	                    </div>
	                </div>
	                <div class="w92 jz of mgt10 mgb32">
	                    <p class="w100 tc f12 c9 mgt10">市场交易由《武汉华中石油化工交易中心有限公司》提供服务</p>
	                </div>
                
                </div>
            </article><!--交易-->

            <article class="tabTableAarticle #f2f2f2 w100">
                <table id='cc-tableTittle' class="MyTable redTable w100 pa" border="0" style="top:0px;left:0;z-index:2;margin-top:9px;">
                    <thead class="tabhead w100 c3">
                    <tr>
                        <th style="width:26%"><p class="f11-340 w100 h100 tc">品种/金额</p></th>
                        <th style="width:19%"><p class="f11-340 w100 h100 tc">数量/性质</p></th>
                        <th><p class="f11-340 w100 h100 tc">订货价/当前价</p></th>
                        <th style="width:30%"><p class="f11-340 w100 h100 tc">浮动盈亏/盈亏比</p></th>
                    </tr>
                    </thead>
                </table>
                 <table id='cc-tableTittleUp' class="MyTable redTable w100 pf" border="0" style="left:0;top: 45px; z-index: 2;display:none;">
                    <thead class="tabhead w100 c3">
                    <tr>
                       <th style="width:26%"><p class="f11-340 w100 h100 tc">品种/金额</p></th>
                        <th style="width:19%"><p class="f11-340 w100 h100 tc">订单/性质</p></th>
                        <th><p class="f11-340 w100 h100 tc">订货价/当前价</p></th>
                        <th style="width:30%"><p class="f11-340 w100 h100 tc">浮动盈亏/盈亏比</p></th>
                    </tr>
                    </thead>
                </table>
                <div id='OpenOrder'>
                	
                </div>
            </article><!--持仓-->
            
  <div id="sellDialog" class="dialog pf w100 h100">
    <section class="jz of bcf">
        <div class="dialogTittle tc jz">
            提示
        </div>
        <div class="content jz lh18 f14 of">
            <div class="w100 clearfix of">
               <p class="f14 c6 fl">确定转让？</p>
            </div>
        </div>
        <div class="button w100 of clearfix">
            <button id="sure" onclick="sellVrOrder();" class="fl cf f15" style="width: 50%">确定</button>
            <button id="cancel" onclick="DialogClose($('#sellDialog'),$('.theme-popover-mask'))" class="fl cf f15" style="width: 50%;background: #CDCDCD;">取消</button>
        </div>
    </section>
</div>           
            
            
            
            <article class="#f2f2f2 w100" style="width: 100%;margin-bottom: 0;" >
            <table id='tableTittleUp' class="greenTable w100 pf" border="0" style="top:45px;;z-index:2;display:none" >
                 <thead class="tabhead w100 c3">
                    <tr>
                        <th style="width:26%"><p class="f11-340 w100 h100 tc">金额/手续费</p></th>
                        <th style="width:19%"><p class="f11-340 w100 h100 tc">数量/性质</p></th>
                        <th><p class="f11-340 w100 h100 tc">订货价/转让价</p></th>
                        <th style="width:30%"><p class="f11-340 w100 h100 tc">订货盈亏/盈亏比</p></th>
                    </tr>
                    </thead>          
            </table>
            <table id='tableTittle' class="greenTable w100 pa" border="0" style="top:0px;left:0;z-index:2;margin-top:9px;" >
                 <thead class="tabhead w100 c3">
                    <tr>
                        <th style="width:26%"><p class="f11-340 w100 h100 tc">金额/手续费</p></th>
                        <th style="width:19%"><p class="f11-340 w100 h100 tc">数量/性质</p></th>
                        <th><p class="f11-340 w100 h100 tc">订货价/转让价</p></th>
                        <th style="width:30%"><p class="f11-340 w100 h100 tc">订货盈亏/盈亏比</p></th>
                    </tr>
                    </thead>          
            </table>
               
            <div id="preOrder" class="w100" style="margin-top:45px;"></div> 

            </article><!--记录-->
            <article class="w100">
            	<div class="articleJz">
	                <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3">转入金额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="totalvrprinciplelVrRmb"></span>
	                    </div>
	                    <div class="fr cff9933 tl" style="min-width:160px;">
	                        <span class="f12 c3">商城赠券</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="totalvrcashgiftVrRmb"></span>
	                    </div>
	                </div>
	                <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3">原始总额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="totalVrRmb"></span>
	                    </div>
	                </div>  
	                
	                             
	                           
	                <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3">当前总额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="netvalueRmb"></span>
	                    </div>
	                    <div class="fr cff9933 tl" style="min-width:160px;">
	                        <span class="f12 c3">可用余额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="balanceRmb"></span>
	                    </div>
	                </div>
	                <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                        <span class="f12 c3">占用金额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="usedRmb"></span>
	                    </div>
	                </div> 
	                
	                
	                <div class="jydiv clearfix of">
	                    <div class="fl cred">
	                        <span class="f12 c3">交易盈亏</span><span class="mgl7 f14">&yen;</span><span
	                            class="f18"></span><span class="f14" id="totalplVrRmb"></span>
	                    </div>
	                    <div class="fr cred tl" style="min-width:160px;">
	                        <span class="f12 c3">盈亏率</span><span class="mgl7 f14"></span><span class="f14" id="totalVrfplRmbRate"></span><span
	                            class="f14"> %</span>
	                    </div>
	                </div>
	                <div class="jydiv clearfix of">
	                    <div class="fl cff9933">
	                    	<span class="f12 c3">可转金额</span><span class="mgl7 f14">&yen;</span><span
	                            class="f14" id="withdrawRmb"></span><span class="f14" ></span>
	                    </div>
	                </div>
	                
	                
	    
	                <div class="vciLine w92 jz pr" style="margin-top: 30px;">
	                </div>
	                <div class="w92 jz of mgt10 mgb32">
	                    <p class="w100 tc f12 c9 mgt10">您为合作方[七彩云购]用户，转出将转至您的七彩云购账户</p>
	                </div>
	                <div class="clearfix of">
	                    <div class="vsDiv pr of">
	                        <a href="mb/jsp/saveMoney.jsp" class="db f16 cf tc fl" style="background:#ff9933">金额转入</a>
	                        <a href="javascript:void(0)" onclick="outFundsDialog();" class="db f16 cf tc fr" style="background:#3399ff">金额转出</a>
	                    </div>
	                </div>
	
	            </article><!--我的资产-->
	        </div>
            </article>
    </section>
    


    <script>
        
        $(function () {
        	 var $tableTop  = $(".jiaoyiTab_content").offset().top -250;
  			
            //            固定表头
            var flag;          
			$(window).scroll(function(){
						var h=$(this).scrollTop();//获得滚动条距top的高度
						if (flag == 1) {
						 if(h > $tableTop ){
						        $("#cc-tableTittleUp").fadeIn();
						        $("#cc-tableTittle").fadeOut();
						    }else{
						    	$("#cc-tableTittleUp").fadeOut();
						        $("#cc-tableTittle").fadeIn();
						    }
						
						}
						else if(flag == 2){
						 if(h > $tableTop){
						       
						        $("#tableTittleUp").fadeIn();
						        $("#tableTittle").fadeOut();
						    }else{
						    	$("#tableTittleUp").fadeOut();
						        $("#tableTittle").fadeIn();
						    }
						}   	   
			});
			
           //            tab切换

            $('.jiaoyiTab>li').click(function () {
                var $t = $(this).index();
                var iconImg = $(this).children('img');
                switch ($t) {
                    case 0:
                        $("#jiaoyi").attr("src", "mb/images/jiaoyi1.png");
                        $("#chicang").attr("src", "mb/images/chicang.png");
                        $("#jilu").attr("src", "mb/images/jilu.png");
                        $("#wodezichan").attr("src", "mb/images/wodezichan.png");
                        break;
                    case 1:
                        flag = 1;
                        $("#jiaoyi").attr("src", "mb/images/jiaoyi.png");
                        $("#chicang").attr("src", "mb/images/chicang1.png");
                        $("#jilu").attr("src", "mb/images/jilu.png");
                        $("#wodezichan").attr("src", "mb/images/wodezichan.png");
                        break;
                    case 2:
                         flag = 2;
                        $("#jiaoyi").attr("src", "mb/images/jiaoyi.png");
                        $("#chicang").attr("src", "mb/images/chicang.png");
                        $("#jilu").attr("src", "mb/images/jilu1.png");
                        $("#wodezichan").attr("src", "mb/images/wodezichan.png");
                        break;
                    case 3:
                        $("#jiaoyi").attr("src", "mb/images/jiaoyi.png");
                        $("#chicang").attr("src", "mb/images/chicang.png");
                        $("#jilu").attr("src", "mb/images/jilu.png");
                        $("#wodezichan").attr("src", "mb/images/wodezichan1.png");
                        break;
                }
                
                switch($t)
                        {
                        	case 0:
                        		openOrders=[];
	                        	loadMyVrInfo();
	                        	break;
                         	case 1:
	                         	loadMyVrOpen();
	                        	break;                       	
                         	case 2:
                         		openOrders=[];
                         		loadMyVrHistoryFinishOrder();
	                         	//loadMyVrPreOrder();
	                        	break;
                         	case 3:
                         		openOrders=[];
	                         	loadMyUserFundInfo();
	                        	break;
                       	                       
                        }


                $('.jiaoyiTab>li').removeClass();
                $(this).addClass('jiaoyiTab_current');
                $('.jiaoyiTab_content>article').css('display', 'none');
                $('.jiaoyiTab_content>article').eq($t).css('display', 'block');
            });
        });



    var vrGoodsList=[];//所有资产品种大类小类商品参数
    var vrGoodsListTmp=[];
    var cfgObj={}; //当前选择的资产品种大类小类商品参数
    var quotes=[]; //所有资产大类的大盘行情基础数据
    var userVrfund={};//交易所帐户资金
    var userShopfund={};//商城帐户资金
    var openOrders=[]; //持仓


    
    function Dialog(dialog,mask) {
        var dialog = dialog;
        var mask = mask;
        mask.fadeIn();
        dialog.slideDown();
    }
    function DialogClose(dialog,mask) {
        var dialog = dialog;
        var mask = mask;
        mask.fadeOut();
        dialog.slideUp();
        ordersnVal=0;orderamountVal=0;goodscodeVal=0;
    }
    function  zhaiPai(kolor,btn){
    	//console.log(btn);
    	if(kolor==0){
    		$("#redTest-pai").show();
    		$("#greenTest-pai").hide();
    	}else if(kolor==1){
    		$("#redTest-pai").hide();
    		$("#greenTest-pai").show();
    	}
    }
    /**卖出界面当价格、数量改变,更新投资金额**/
    function UpdateSellRmb()
    {
       var sellNumVal= $.trim($("#sellNum").val());
       if(sellNumVal=='' || sellNumVal*1.0<=0  )
       {
        	return;
       }
       var sellPriceVal=$.trim($("#sellPrice").val());
       if(sellPriceVal=='' || isNaN(sellPriceVal*1.0)){
            $("#sellPrice").val(1);
            return false;    
       }
       $("#totalSellprice").html(sellNumVal*1.0*sellPriceVal);
       
    }
    
     function setTotal(countVal,price,danjia) {

        var price = price;
        var danjia = danjia;
        var danjiaPrice = danjia.val();
        
        var countVal = countVal;
        var priceTotal = danjiaPrice*countVal;
        //console.log(danjiaPrice);
        price.text(priceTotal);
    }
    function addCount(count,price,danjia) {
        var count = count;
        var price = price;
        var danjia = danjia;
        count.val(parseInt(count.val())+1);
        var countVal = count.val();
        setTotal(countVal,price,danjia);
    }
    function minCount(count,price,danjia) {
        var count = count;
        var price = price;
        var danjia = danjia;

        count.val(parseInt(count.val())-1);
        if(parseInt(count.val())<1){
            count.val(1);
        }
        var countVal = count.val();
        setTotal(countVal,price,danjia);
    }
    function inputChange(count,price,danjia) {
        var count = count;
        var price = price;
        var danjia = danjia;
        var patten = /^[0-9]*[1-9][0-9]*$/;
        if(!(patten.test(count.val()))){
            count.val(1);
        }
        var countVal = count.val();
        setTotal(countVal,price,danjia);
    }
    
    
     
    function SetcfgObj(selValue)
 	{
 		
 		
 		var arrayValue=selValue.split('&');
 		var groupid=arrayValue[0];
 		var goodscode=arrayValue[1];
 		$.each(vrGoodsList, function(index, objVal) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
	    
		    if(objVal.bid==groupid && objVal.NF2L1CI==goodscode) {
				cfgObj=objVal;
				if(cfgObj.paramChage.NF2R*1.0==1) //固定手续费
				{
					$("#opencharge").html(''+cfgObj.paramChage.NF2M1EY*cfgObj.paramChage.NF2M1C2);
					$("#closecharge").html(''+cfgObj.paramChage.NF2R1C6*cfgObj.paramChage.NF2M1C2);
				}
				else//49 百分比续费
				{
					$("#opencharge").html(''+(100.0*cfgObj.paramChage.NF2M1EY)+'%'); //万分之
					$("#closecharge").html(''+(100.0*cfgObj.paramChage.NF2R1C6)+'%');
				}
				$("#num").attr('placeholder','最大'+getMrInt(cfgObj.paramChage.NF2H1C4));
				UpdateBuyRmb();
				return ;
		    }
   		 
		});
		
 		
 	}
 	
 	var isReadyFlag=false;
 	var tradeFlist=[];
    $().ready(function() { 
    
   		$("#redTest-pai").show();
   		$("#greenTest-pai").hide();
    		
          var accountVal="<%=user.useraccount%>";
		  var pwdVal="<%=pwdMd5%>";
		  
		  var directivesVal={NF2W18G:accountVal,NF37:pwdVal};
		  directivesVal='['+JSON.stringify({NF2S:"NF2B4F",NF3A:directivesVal})+']';
		  //console.log(directivesVal);
    	//交易所登陆
		$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
            //console.log("交易所登陆");
            //console.log(data);
            var NF3C=data[0].NF3C;
            var NF34=data[0].NF34;
            //console.log(NF3C);
            //console.log(NF3C.substr(2,1));
    		var state=NF3C.substr(2,1)*1.0;
              if(state==0)
              {
              	var mt_tokenVal=data[0].NF2W.NF3D1B1;//mt_token
              	//更新token
		        $.ajax({
		            url: "PlugServlet",
		            data: ''+JSON.stringify({m:1788,mt_token:mt_tokenVal}),
		            type: 'post',
		            dataType: 'json',
		            contentType:"application/json;charset=utf-8",
		            beforeSend: function () {
		            },
		            success: function (data) {
		              if(data['state']==1)
		              {
		              		getInitData();
		              }
					  else{
						  layer.alert(data.info);
					  }
					  	
		             },
		            error: function (data) {
		                showToast('网络忙，请重试');
		            },
		            complete: function () {
		            }
		        }); 

              }
			  else
			  {
			  	//dealErrorCode(NF3C);
			  	layer.alert(NF34);
			  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
        
     var IsReadytimer=setTimeout(function(){
			if(isReadyFlag)
			{
				intDate();
			}
			console.log("循环监测     "+isReadyFlag);
			if(!isReadyFlag)IsReadytimer=setTimeout(arguments.callee,500);
			
		},500);
  
  	}); 
  	/** 行情列表 **/
  	function getFlist()
  	{
  	    //行情列表
		$.ajax({
            url: "/api/v1/market/list",
            data: {bid:"*"},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
            	//console.log("行情列表");
            	//console.log(data);
            	tradeFlist=data;
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
  	}
  	
  	function getInitData()
  	{
  		getFlist();
  		loadVrGoods();
		loadMyVrInfo(); 
  	
  	}
  	
  	function intDate()
  	{
  		/**资产产品信息整合与行情关联 **/
  		$.each(vrGoodsListTmp, function(index0, objVal0) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
			$.each(tradeFlist, function(index1, objVal1) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
				if(objVal0.NF2L1CI==objVal1.wid)
				{
					objVal0.bid=objVal1.bid;
					objVal0.wid=objVal1.wid;
				}
			});
		});
		//console.log("新的资产品种");
  		//console.log(vrGoodsListTmp);
  		/** 资产产品 数据加载显示 **/
  		vrGoodsList=vrGoodsListTmp;
  		/* 					
		vrGoodsList.sort(function(a, b) {
		       var ai = a.showorder*1.0;
		       var bi = b.showorder*1.0;
		                if (ai > bi) {
		                    return 1;
		                } else if (ai < bi) {
		                    return -1;
		                } else {
		                    return 0;
		                }

		}); 
		*/
		var contentHtml="";            
		var splitStr="&";
	    $.each(vrGoodsList, function(index, objVal) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
	           		    //value=groupid & goodscode
		           		if(index==0) {
		           			contentHtml=contentHtml+'<option style="height:40px;" value ="'+objVal.bid+splitStr+objVal.NF2L1CI+'" selected="selected">'+objVal.NF2N1CJ+'</option>';
		           			
		           			SetcfgObj(objVal.bid+splitStr+objVal.NF2L1CI);
	           				chartsinit(cfgObj);
		           		}
		           		else
		           		{
		           			contentHtml=contentHtml+'<option style="height:40px;" value ="'+objVal.bid+splitStr+objVal.NF2L1CI+'" >'+objVal.NF2N1CJ+'</option>';
		           		}
	           		 
		});
	    $("#proKind").html(contentHtml);
  	}
  	
  	
  	
    /**取资产产品**/
 	function loadVrGoods()
 	{
		  var directivesVal='['+JSON.stringify({NF2S:"NF2BVG"})+']';
		  //console.log(directivesVal);
		  
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取资产产品");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              	//数据
	           		$("#proKind").html('');
					var contentHtml="";
					if(data[0].NF2W==null || data[0].NF2W.NF3G1FJ==null)  return;
					vrGoodsListTmp=data[0].NF2W.NF3G1FJ;
					//取每个资产品种的详情信息，手续费等信息
					getVrGoodsDetailInfo("*");
					
	              }
				  else{
					  	//dealErrorCode(NF3C);
			  			layer.alert(NF34);
					  	$("#proKind").html('');
				  }
				  	
	             },
	            error: function (data) {
	                showToast('网络忙，请重试');
	            },
	            complete: function () {
	            }
	        }); 
  	
 	}  	
  	       
  	//取某个资产品种的手续费等信息
  	function getVrGoodsDetailInfo(wid)
  	{
  		var directivesVal={NF2L1D8:wid,NF2H1E8:"0"};
		directivesVal='['+JSON.stringify({NF2S:"NF2BVF",NF3A:directivesVal})+']';
		//console.log(directivesVal);
		  
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取某资产产品手续费等信息");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
		              	if(data[0].NF2W!=undefined && data[0].NF2W!=null && data[0].NF2W.NF3G1FJ!=undefined && data[0].NF2W.NF3G1FJ!=null)
		              	{
		              		var tmpList=data[0].NF2W.NF3G1FJ;
		              		$.each(vrGoodsListTmp, function(index, objVal) 
							{
								for(var i=0;i<tmpList.length;i++)
								{
									if(objVal.NF2L1CI==tmpList[i].NF2M1EB)
								    {
								      	objVal.paramChage=tmpList[i];
								      	break;
								    }
								}
	
							});
							isReadyFlag=true;
		              	}
	              }
				  else{
					  	//dealErrorCode(NF3C);
			  			layer.alert(NF34);
				  }
				  	
	             },
	            error: function (data) {
	                showToast('网络忙，请重试');
	            },
	            complete: function () {
	            }
	        }); 
  	
  	}
  	
      /**购买界面当价格、数量改变,更新投资金额**/
    function UpdateBuyRmb()
    {
       var numVal= $.trim($("#num").val());
       if(numVal=='' || numVal*1.0<=0  )
       {
        	$("#totalBuyRmb").html("");
       		$("#totalBuyRmbRate").html("");
        	return;
       }
        var directValue  = $('input[name="direct"]:checked').val();
        
    	var priceVal=$.trim($('#price').val());
    	
    	var priceVal=cfgObj.paramChage.NF2M1C2*1.0*cfgObj.paramChage.NF2M1EI;

        if(cfgObj.paramChage.NF2R*1.0==1) //固定手续费
		{
			$("#totalBuyRmbRate").html(getMrZear(numVal*1.0*cfgObj.paramChage.NF2M1EY*cfgObj.paramChage.NF2M1C2));
		}
		else//49 百分比续费
		{
			$("#totalBuyRmbRate").html(getMrZear(numVal*1.0*priceVal*cfgObj.paramChage.NF2M1EY));
		}
		
       $("#totalBuyRmb").html(getMrZear(numVal*1.0*priceVal));
       
       
    }       
        
        
     /**交易界面 取我的理财资产**/
    function loadMyVrInfo0()
    {
    
       $.ajax({
            url: "PlugServlet",
            data: ''+JSON.stringify({m:272}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
              if(data['state']==1)
              {
              		$('#totalenablermb').html(data.obj.vrnowrmb);
              }
			  else{
				  showToast(data.info);
				  $('#totalenablermb').html("0");
			  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }      
        
    
    /**建仓**/
    function Buy()
    {
    
    	var directValue  = $('input[name="direct"]:checked').val();
    	var priceVal=$.trim($("#price").val());
    	var numVal= parseInt($.trim($("#num").val()));
    	 //止盈
       var tppercentVal= parseInt($.trim($("#tppercent").val()));
       //止损
       var slpercentVal= parseInt($.trim($("#slpercent").val()));
        
       if(isNaN(numVal) )
       {
       		showToast("数量不能为空");
       		return;
       }
       if(isNaN(tppercentVal))
       {
       		showToast("止盈不能为空");
       		return;
       }
       if(tppercentVal*1.0==0)
       {
       		showToast("止盈 不能为0。");
       		return;
       }
       if(tppercentVal*1.0>100)
       {
       		showToast("止盈  不超过100。");
       		return;
       }
       if(isNaN(slpercentVal))
       {
       		showToast("止损不能为空");
       		return;
       }
       if(slpercentVal*1.0>90)
       {
       		showToast("止损 不超过90。");
       		return;
       }
       if(slpercentVal*1.0==0)
       {
       		showToast("止损 不能为0。");
       		return;
       }
       if(numVal<=0)
       {
        	showToast("数量不正确。");
        	return;
       } 
       var buyrmb=$("#totalBuyRmb").html();
       var changermb=$("#totalBuyRmbRate").html();
       var totalrmb=$("#totalenablermb").html();
        
       
       if(totalrmb*1.0<(buyrmb*1.0+changermb*1.0))
       {
       		showToast("资金不足。");
        	return;
       }
    	
    	var directivesVal={NF1W:directValue,NF2L1D8:cfgObj.wid,NF2D1D9:priceVal,NF291DA:numVal,NF2J1DB:tppercentVal,NF22:slpercentVal};
		directivesVal='['+JSON.stringify({NF2S:"NF2BV3",NF3A:directivesVal})+']';
		//console.log(directivesVal);
		  
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("市价建仓");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              	showToast('成功');
	                $("#num").val('');
	       			$("#tppercent").val('');
	       			$("#slpercent").val('');
				    $("#totalBuyRmb").html("");
				    $("#totalBuyRmbRate").html("");
				    
				    setTimeout(function(){
								loadMyVrInfo();
								},1000);
	              }
				  else{
					  	//dealErrorCode(NF3C);
			  			layer.alert(NF34);
				  }
				  	
	             },
	            error: function (data) {
	                showToast('网络忙，请重试');
	            },
	            complete: function () {
	            }
	        }); 
     } 
     
      
	 /**取我的理财委托**/
    function loadMyVrPreOpen()
    {
     	var directivesVal='['+JSON.stringify({NF2S:"NF2BVA"})+']';
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取我的委托");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              
	              
	              }
				  else
				  {
				  	//dealErrorCode(NF3C);
				  	layer.alert(NF34);
				  	$("#OpenOrder").html('');
					openOrders=[];
				  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }   
    
 	 /**取我的理财委托成交**/
    function loadMyVrPreOpenSuccess()
    {
     	var directivesVal='['+JSON.stringify({NF2S:"NF2BVB"})+']';
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取我的委托成交");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              		
	              
	              }
				  else
				  {
				  	//dealErrorCode(NF3C);
				  	layer.alert(NF34);
				  	$("#OpenOrder").html('');
					openOrders=[];
				  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }      
    
    
    /**取我的理财持仓**/
    function loadMyVrOpen()
    {

     	var directivesVal='['+JSON.stringify({NF2S:"NF2BVC"})+']';
		//console.log(directivesVal);
		  
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取我的持仓");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              	//数据
	           		$("#OpenOrder").html('');
					var contentHtml="";
					openOrders=[];
					if(data[0].NF2W==undefined || data[0].NF2W==null || data[0].NF2W.NF3G1FJ.length==0)  return;
					var ordersListTmp2=data[0].NF2W.NF3G1FJ;
					//数据补充处理
					var vrGoodsListTmp=vrGoodsList;
					$.each(ordersListTmp2, function(index, objVal) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
	           		        for(var i=0;i<vrGoodsListTmp.length;i++)
	           		        {
	           		        	if(vrGoodsListTmp[i].wid==objVal.NF2M1EB && objVal.NF261F3*1.0==0)
	           		        	{  
	           		        		objVal.bid=vrGoodsListTmp[i].bid; //增加商品大类属性
	           		        		objVal.wid=vrGoodsListTmp[i].wid; //增加商品大类属性
	           		        		objVal.NF2M1C2=vrGoodsListTmp[i].paramChage.NF2M1C2; //增加商品合约单位
	           		        		objVal.NF2B1CL=vrGoodsListTmp[i].NF2B1CL;
	           		        		if(vrGoodsListTmp[i].paramChage.NF2R1C7*1.0==2)
	           		        			objVal.agreeunit=1/vrGoodsListTmp[i].paramChage.NF2M1EI;
	           		        		else
	           		        			objVal.agreeunit=vrGoodsListTmp[i].paramChage.NF2M1EI;
	           		        		objVal.agreeunit=vrGoodsListTmp[i].paramChage.NF2M1C2; //增加商品合约单位
	           		        		openOrders.push(objVal);
	           		        		break;
	           		        	}
	           		        }
					});
					openOrders.sort(function(a, b) 
					{
						var ai = a.NF221EO*1.0;
						var bi = b.NF221EO*1.0;
							                
						if (ai > bi) {
							 return -1;
						} else if (ai < bi) {
							 return 1;
						} else {
							return 0;
						}
					});
					
					//生成html
					createHtmlForOpenOrder();
              }
			  else
			  {
			  	//dealErrorCode(NF3C);
			  	layer.alert(NF34);
			  	$("#OpenOrder").html('');
				openOrders=[];
			  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }   

    
  	/**平仓**/
    function sellVrOrderDialog(type,ordersnV,orderamountV,goodscodeV,dateVal)
    {
       	layer.confirm('确定转让吗?', function(){ 
			sellVrOrder(type,ordersnV,orderamountV,goodscodeV,dateVal);
			layer.closeAll();
		});
    }
    
    /**持仓卖出即平仓**/
    function sellVrOrder(type,ordersnVal,orderamountVal,goodscodeVal,dateVal)
    {
    	var directValue="S";
    	var priceVal=$.trim($('#nowprice2').html());
    	if(type*1.0==2)
    	{
    		directValue="B";
    		priceVal=$.trim($('#nowprice1').html());
    	}
        var directivesVal={NF1W:directValue,NF2L1D8:goodscodeVal,NF2D1D9:priceVal,NF291DA:orderamountVal,NF211DH:ordersnVal,NF231DG:dateVal};
		directivesVal='['+JSON.stringify({NF2S:"NF2BV4",NF3A:directivesVal})+']';
		//console.log(directivesVal);
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("平仓");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              	 showToast("转让成功");
              		 setTimeout(function(){
              		 	openOrders=[];
						loadMyVrHistoryFinishOrder();
              		 	loadMyVrOpen();
              		 	loadMyVrInfo();
							
					},1000);
	              
	              }
				  else
				  {
				  	//dealErrorCode(NF3C);
				  	layer.alert(NF34);
				  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
  
    }        
  
    
        
        
        
        
 /**取我的理财资产(交易所帐户)**/
    function loadMyVrInfo()
    {
    	var directivesVal='['+JSON.stringify({NF2S:"NF2BVE"})+']';
		//console.log(directivesVal);
		  
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	          if(state==0)
              {
              	userVrfund=data[0].NF2W;
              	$('#totalenablermb').html(userVrfund.NF291BZ);
              }
			  else
			  {
			  	//dealErrorCode(NF3C);
			  	layer.alert(NF34);
			  }
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }       
        
  
    //生成html 
    function createHtmlForOpenOrder()
    {
      	if(openOrders.length==0) return;
     	$("#OpenOrder").html('');
    	var contentHtml='';
    	//console.log(openOrders);
    	
    	$.each(openOrders, function(index, objVal) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
    		               
    		                var close=0;
	           		        for(var i=0;i<quotes.length;i++)
	           		        {
	           		        	if(quotes[i].bid==objVal.bid && quotes[i].wid==objVal.wid)
	           		        	{   
	           		        		close=quotes[i].c;
	           		        		break;
	           		        	}
	           		        }
	           		        
	           		         var openprice=objVal.NF251EU;
	           		         var shareRmb=0;//浮动盈亏
	           		         
	           		         //console.log(objVal.agreeunit+"   "+objVal.NF281F4+"  "+close+"  "+openprice);
	                         if(objVal.NF221ED*1.0==1) //是买涨
	                         {
	                         	shareRmb=objVal.agreeunit*objVal.NF281F4*(close*1.0-openprice*1.0);
	                         }
	                         else //是买跌
	                         {
	                         	shareRmb=objVal.agreeunit*objVal.NF281F4*(openprice*1.0-close*1.0);
	                         }
							 
							 
							 
							 var shareRmbRate=0; //浮动盈亏率
							 shareRmbRate=100*shareRmb/(objVal.NF2M1EI);//百分比
	           		         shareRmbRate=getMrZear(shareRmbRate);
	           		         shareRmb=getMrZear(shareRmb);
	           		         
	           		         var chargermb=0;//手续费
                             chargermb=Math.abs(objVal.NF2M1EY*1.0);
                           
                           
                       // if(shareRmbRate>(0-objVal.slpercent*1.0) && shareRmbRate<objVal.tppercent*1.0)
                       //{
                       		contentHtml=contentHtml+'<table class="greenTable" border="0">'+
					                    '<tbody class="f12 c9">'+
					                    '<tr>'+
					                        '<td style="width:26%;">'+objVal.NF2O1EC+'</td>'+
					                        '<td style="width:19%;">'+getMrZear(objVal.NF281F4)+'</td>'+
					                        '<td>'+getMrZear(objVal.NF251EU)+'</td>';
					                        
							    if(shareRmb>=0)
								{           
										contentHtml=contentHtml+'<td style="width:30%;" class="cred">'+shareRmb+'</td>';
										
								}else
								{
										contentHtml=contentHtml+'<td style="width:30%;" class="cgreen">'+shareRmb+'</td>';
								}                   
								                        
							                        
							                        
							            contentHtml=contentHtml+'</tr>'+
							                    '<tr>'+
							                        '<td style="width:26%;">'+getMrZear(objVal.NF2M1EI)+'('+chargermb+')</td>';
		
							                        
							    if(objVal.NF221ED*1.0==1)
			                        	contentHtml=contentHtml+'<td style="width:19%;" class="cred">采购</td>';
			                    else
			                        	contentHtml=contentHtml+'<td style="width:19%;" class="cgreen">销售</td>';
			                        	
							            
							            
							            
							    if(close*1.0>=openprice*1.0)
			                    {
			                         	contentHtml=contentHtml+'<td class="cred">'+getMrZear(close)+'</td>';
			                    }
			                    else
			                    {
			                         	contentHtml=contentHtml+'<td class="cgreen">'+getMrZear(close)+'</td>';
			                    }        
							    if(shareRmb>=0)
								{           
										contentHtml=contentHtml+'<td style="width:30%;" class="cred">'+shareRmbRate+'%</td>';
										
								}else
								{
										contentHtml=contentHtml+'<td style="width:30%;" class="cgreen">'+shareRmbRate+'%</td>';
								}
							                        
					            contentHtml=contentHtml+'</tr>'+
					                    '</tbody>'+
					                    '<tfoot>'+
					                    '<tr>'+
					                        '<td colspan="3"><p class="f12 c9 fl">&nbsp;&nbsp;&nbsp;&nbsp;成交时间&nbsp;&nbsp;'+objVal.NF2M1F8+'</p></td>'+
					                        '<td class="f13" colspan="1" style="color:#0066ff;"><a href="javascript:void(0);" onclick="sellVrOrderDialog(\''+objVal.NF221ED+'\',\''+objVal.NF221EO+'\',\''+objVal.NF281F4+'\',\''+objVal.wid+'\',\''+objVal.NF241EN+'\');">转让</a></td>'+
					                    '</tr>'+
					                    '</tfoot>'+
					                '</table>'+
					                '<section class="w100 tableLine"></section>';
                       
                       //}    
 		
		});
		$("#OpenOrder").html(contentHtml);
				    
				    
	           		
    }
    
    /**取我的 当天或历史  盈亏记录**/
    function loadMyVrHistoryFinishOrder(day)
    {
    	//先查得当天的平仓成交
    	var directivesVal='['+JSON.stringify({NF2S:"NF2BVB"})+']';
	 	$.ajax({
            url: "/mtrade-service/api",
            data: {directives:directivesVal},
            type: 'post',
            dataType: 'json',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
	            beforeSend: function () {
	            },
	            success: function (data) {
	            	//console.log("取我的当天成交");
	            	//console.log(data);
	              	var NF3C=data[0].NF3C;
            		var NF34=data[0].NF34;
    				var state=NF3C.substr(2,1)*1.0;
	              if(state==0)
	              {
	              		var contentHtml="";
						var finishOrder=[];
						var listTmp=[];
						if(data[0].NF2W==undefined || data[0].NF2W==null || data[0].NF2W.NF3G1FJ==undefined || data[0].NF2W.NF3G1FJ==null || data[0].NF2W.NF3G1FJ.length==0) 
						{
							listTmp=[];
						}
						else
						{
							listTmp=data[0].NF2W.NF3G1FJ;
						}
    					var startday='<%=startdayVal%>';
    					var endday='<%=enddayVal%>';
    
	              		var directivesVal={NF241FP:startday,NF251FQ:endday};
						directivesVal='['+JSON.stringify({NF2S:"NF2BVL",NF3A:directivesVal})+']';
					 	$.ajax({
				            url: "/mtrade-service/api",
				            data: {directives:directivesVal},
				            type: 'post',
				            dataType: 'json',
				            contentType:"application/x-www-form-urlencoded;charset=utf-8",
					            beforeSend: function () {
					            },
					            success: function (hisdata) {
					            	//console.log("取我的历史成交");
					            	//console.log(hisdata);
					              	var NF3C=hisdata[0].NF3C;
				            		var NF34=hisdata[0].NF34;
				    				var state=NF3C.substr(2,1)*1.0;
					              if(state==0)
					              {
					              		var hislistTmp=[];
										if(hisdata[0].NF2W==undefined || hisdata[0].NF2W==null || hisdata[0].NF2W.NF3G1FJ==undefined || hisdata[0].NF2W.NF3G1FJ==null || hisdata[0].NF2W.NF3G1FJ.length==0) 
										{
											hislistTmp=[];
										}
										else
										{
											hislistTmp=hisdata[0].NF2W.NF3G1FJ;
										}
										
										listTmp=listTmp.concat(hislistTmp);
									   //再从成里过滤出平仓的。
					              		$.each(listTmp, function(index, objVal) 
										{
											 if(objVal.NF24*1.0==2)
											 {
											      finishOrder.push(objVal);
											      return;
											 }
										});
										if(finishOrder.length==0)
										{
											return;
										}
										
										$.each(finishOrder, function(index, objVal) 
										{
											 for(var i=0;i<vrGoodsList.length;i++)
											 {
											 	if(objVal.NF2M1EB==vrGoodsList[i].NF2L1CI && vrGoodsList[i].paramChage!=undefined)
											 	{
											 		objVal.NF2M1C2=vrGoodsList[i].paramChage.NF2M1C2;
											 		break;
											 	}
											 }
										});
										
										
										
										finishOrder.sort(function(a, b) {
											//2017-03-28 22:56:05  20170328225605
											var aStr=a.NF2M1F1;
											var bStr=b.NF2M1F1;
											aStr=aStr.replace('-','');
											aStr=aStr.replace('-','');
											aStr=aStr.replace(':','');
											aStr=aStr.replace(':','');
											aStr=aStr.replace(' ','');
										
											bStr=bStr.replace('-','');
											bStr=bStr.replace('-','');
											bStr=bStr.replace(':','');
											bStr=bStr.replace(':','');
											bStr=bStr.replace(' ','');
									
							                var ai = aStr*1.0;
							                var bi = bStr*1.0;
							                
							                if (ai > bi) {
							                    return -1;
							                } else if (ai < bi) {
							                    return 1;
							                } else {
							                    return 0;
							                }
					
							            });
								    
					           		$.each(finishOrder, function(index, objVal) { //遍历对象数组，index是数组的索引号，objVal是遍历的一个对象。
					           		
					           		contentHtml=contentHtml+'<table class="greenTable w100" border="0">'+ 
					           		 					'<col width="26%"><col width="19%"><col width="25%"><col width="30%">'+
								                         '<thead class="insetThead f12 c9 w100">'+
														 '<tr class="w100">'+
														 	'<td colspan="2">&nbsp;&nbsp;&bull;&nbsp;单号：'+objVal.NF2K1ET+'</td>'+
														 	'<td colspan="2" class="tr">'+objVal.NF2O1EC+'&nbsp;&nbsp;</td>'+
														 '</tr>'+
														'</thead>'+
									                    '<tbody class="f12 c9 w100">'+
									                    '<tr>'+
									                        '<td>'+getMrZear(objVal.NF2M1EI)+'</td>'+
									                        '<td>'+getMrZear(objVal.NF2L1FO)+'</td>'+
									                        '<td>'+getMrZear(objVal.NF251EU)+'</td>';
				
											  var shareRmb=0;//结算盈亏
											  if(objVal.NF2M1F1=='')         
											  {
											  		shareRmb=objVal.clearpl/objVal.fixedNumber;
											  }
											  else
											  {
											  		shareRmb=objVal.pl/objVal.fixedNumber;
											  }     
				
				                             if(objVal.NF221ED*1.0==2) //是买涨
					                         {
					                         	shareRmb=objVal.NF2M1C2*objVal.NF2L1FO*(objVal.NF281EW*1.0-objVal.NF251EU*1.0);
					                         }
					                         else //是买跌
					                         {
					                         	shareRmb=objVal.NF2M1C2*objVal.NF2L1FO*(objVal.NF251EU*1.0-objVal.NF281EW*1.0);
					                         }	 										
				
											 var shareRmbRate=0; //盈亏率
											 shareRmbRate=100*shareRmb/(objVal.NF2M1EI);//百分比 
									                        
									         var chargermb=0;//手续费
				                             chargermb=Math.abs(objVal.NF2M1EY*1.0);                
									           
									                        
									    if(shareRmb>=0)
										{           
												contentHtml=contentHtml+'<td class="cred">'+getMrZear(shareRmb)+'</td>';
												
										}else
										{
												contentHtml=contentHtml+'<td class="cgreen">'+getMrZear(shareRmb)+'</td>';
										}                   
										                        
									                        
									                        
									            contentHtml=contentHtml+'</tr>'+
									                    '<tr>'+
									                        '<td>'+chargermb+'</td>';
				
									                        
									    if(objVal.NF221ED*1.0==2)
					                        	contentHtml=contentHtml+'<td  class="cred">采购转让</td>';
					                    else
					                        	contentHtml=contentHtml+'<td class="cgreen">销售转让</td>';
					                        	
									            
									    if(objVal.closetime=='')         
										{        
													contentHtml=contentHtml+'<td >--</td>';
									    }  
									    else
									    {   
										    if(objVal.NF281EW*1.0>=objVal.NF251EU*1.0)
						                    {
						                         	contentHtml=contentHtml+'<td class="cred">'+getMrZear(objVal.NF281EW)+'</td>';
						                    }
						                    else
						                    {
						                         	contentHtml=contentHtml+'<td class="cgreen">'+getMrZear(objVal.NF281EW)+'</td>';
						                    }  
					                    }      
									    if(shareRmb>=0)
										{           
												contentHtml=contentHtml+'<td class="cred">'+getMrZear(shareRmbRate)+'%</td>';
												
										}else
										{
												contentHtml=contentHtml+'<td class="cgreen">'+getMrZear(shareRmbRate)+'%</td>';
										}
									             
									     if(objVal.NF2M1F1=='')         
									     {
									     		contentHtml=contentHtml+'</tr>'+
									                    '</tbody>'+
									                    '<tfoot>'+
									                    '<tr>'+
									                        '<td colspan="3"><p class="f12 c9 fl">&nbsp;&nbsp;转让时间：&nbsp;&nbsp;&nbsp;&nbsp;订单持有&nbsp;&nbsp;&nbsp;&nbsp;</p></td>';
									     }
									     else
									     {
									     		 contentHtml=contentHtml+'</tr>'+
									                    '</tbody>'+
									                    '<tfoot>'+
									                    '<tr>'+
									                        '<td colspan="3"><p class="f12 c9 fl">&nbsp;&nbsp;转让时间：'+objVal.NF2M1F1+'</p></td>';
									     }
									               
										 var operType=objVal.NF2G1EZ*1.0;
									     //operType=1 用户操作   2：系统自动 3系统手动
									     if(operType==1)
									     {
									     	contentHtml=contentHtml+'<td class="f12" colspan="1" >用户主动操作</td>';
									     }
									     else if(operType==2)
									     {
									     	contentHtml=contentHtml+'<td class="f12" colspan="1" >系统自动</td>';
									     
									     }
									     else if(operType==3)
									     {
									     	contentHtml=contentHtml+'<td class="f12" colspan="1" >系统手动</td>';
									     
									     }
									      
				   
									            contentHtml=contentHtml+
									                    '</tr>'+
									                    '</tfoot>'+
									                '</table>'+
									                '<section class="w100 tableLine"></section>';
				       
								    });
					           		$("#preOrder").html(contentHtml);
					           		
					              }
			              		  else
								  {
								  	//dealErrorCode(NF3C);
								  	layer.alert(NF34);
								  	$("#preOrder").html('');
									openOrders=[];
								  }
							  	
				             },
				            error: function (data) {
				                showToast('网络忙，请重试');
				            },
				            complete: function () {
				            }
				        }); 
	              }
				  else
				  {
				  	//dealErrorCode(NF3C);
				  	layer.alert(NF34);
				  	$("#preOrder").html('');
					openOrders=[];
				  }
			  	
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
    }        
    
    
    
 /**取我的理财资产(商城帐户与交易所帐户)**/
    function loadMyUserFundInfo()
    {
    	userShopfund={};
    	userVrfund={};
    	
    	$.ajax({
            url: "PlugServlet",
            data: ''+JSON.stringify({m:272}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
              if(data['state']==1)
              {
              		userShopfund=data.obj;
			        var directivesVal='['+JSON.stringify({NF2S:"NF2BVE"})+']';
				 	$.ajax({
			            url: "/mtrade-service/api",
			            data: {directives:directivesVal},
			            type: 'post',
			            dataType: 'json',
			            contentType:"application/x-www-form-urlencoded;charset=utf-8",
				        beforeSend: function () {},
				        success: function (data) {
				            //console.log(data);
				             var NF3C=data[0].NF3C;
			            	 var NF34=data[0].NF34;
			    			 var state=NF3C.substr(2,1)*1.0;
					          if(state==0)
				              {
				              	userVrfund=data[0].NF2W;
				              }
							  else
							  {
							  	//dealErrorCode(NF3C);
							  	layer.alert(NF34);
							  }
			             },
			            error: function (data) {
			                showToast('网络忙，请重试');
			            },
						complete: function () 
			            {
				            //console.log(userShopfund);
					    	//console.log(userVrfund);
					    	    
					    	if(!isEmptyObject(userShopfund) && !isEmptyObject(userVrfund))
					    	{
					 
					    		//更新UI数据
					    		$('#totalvrprinciplelVrRmb').html(getMrZear(userShopfund.vrprinciplelrmb));
					    		$('#totalvrcashgiftVrRmb').html(getMrZear(userShopfund.vrcashgiftrmb1*1.0+userShopfund.vrcashgiftrmb2*1.0));
					    		var total=userShopfund.vrprinciplelrmb*1.0+userShopfund.vrcashgiftrmb1*1.0+userShopfund.vrcashgiftrmb2*1.0;
					    		$('#totalVrRmb').html(getMrZear(total));
					    		
					    		$('#netvalueRmb').html(getMrZear(userVrfund.NF26));
					    		$('#balanceRmb').html(getMrZear(userVrfund.NF291BZ));
					    		$('#usedRmb').html(getMrZear(userVrfund.NF2M1EI));
					    		//$('#chargeRmb').html(getMrZear((userVrfund.inoutcharge*1.0+userVrfund.charge*1.0)/100));
					    		var pl=userVrfund.NF26*1.0-total; //盈亏
					    		
					    		//$('#totalplVrRmb').html(getMrZear(userVrfund.pl*1.0/100));
					    		$('#totalplVrRmb').html(getMrZear(pl));
					    		if(pl==0 || total==0)
					    		{
					    			$('#totalVrfplRmbRate').html('0');
					    		}
					    		else
					    		{
					    			$('#totalVrfplRmbRate').html(getMrZear(100*pl/total));
					    		}
					    		
					    		//$('#withdrawRmb').html(userVrfund.balance/100-userShopfund.vrcashgiftrmb1*1.0+userShopfund.vrcashgiftrmb2*1.0);
								$('#withdrawRmb').html(getMrZear((userVrfund.NF271C0*1.0)));
					    	}
			            
			            }
			        }); 
              		
			            
			        
              }
			  else{
				  layer.alert(data.info);
			  }
			  	
             },
            error: function (data) {
                layer.alert('网络忙，请重试');
            },
            complete: function () 
            {
            }
        }); 
    
    }    
    
   /**出金 对话框**/
    function outFundsDialog()
    {

    	$('#withdrawRmb').html(getMrZear((userVrfund.NF271C0*1.0)));
    	layer.confirm('您确定出金？出金的前提，不能有订单持有!?', function(){ 
			outFunds();
			layer.closeAll();
		});
    } 

    /**出金**/
	function outFunds()
	{
		//先取得当前用户在市场中的市场总资产
		var directivesVal='['+JSON.stringify({NF2S:"NF2BVE"})+']';
		$.ajax({
		    url: "/mtrade-service/api",
		    data: {directives:directivesVal},
			type: 'post',
			dataType: 'json',
			contentType:"application/x-www-form-urlencoded;charset=utf-8",
			beforeSend: function () {},
			success: function (data) {
				var NF3C=data[0].NF3C;
			    var NF34=data[0].NF34;
			    var state=NF3C.substr(2,1)*1.0;
				if(state==0)
				{
				    userVrfund=data[0].NF2W;
			        var netvalueRmb=getMrZear((userVrfund.NF26*1.0));
			        var withdrawRmb=getMrZear((userVrfund.NF26*1.0));
			        doOutFunds(netvalueRmb*1.0,withdrawRmb*1.0);
 			    }
				else
					dealErrorCode(data['retcode']);
			    },
			error: function (data) {
			        layer.alert('网络忙，请重试');
			},
			complete: function () 
			{
			    
			}
		});
	}  
 
 
 function doOutFunds(netRmb,withdrawRmb)
 {
		
		$.ajax({
		            url: "PlugServlet",
		            data: ''+JSON.stringify({m:244,netvalueRmb:netRmb,outRmb:withdrawRmb}),
		            type: 'post',
		            dataType: 'json',
		            contentType:"application/json;charset=utf-8",
		            beforeSend: function () {
		            },
		            success: function (data) {
		              //console.log(data);
		              if(data['state']==1)
		              {
		                showToast(data.info);
	                    setTimeout(function(){
              		 		openOrders=[];
	                    	loadMyUserFundInfo();
						},1000);
		              }
					  else
					  	showToast(data.info);
		             },
		            error: function (data) {
		                showToast('网络忙，请重试');
		            },
		            complete: function () {
		            	
		            }
		        });  
 
 }   
    
    
    

       
    </script>


</div>

</body>
</html>
